package com.gradle.quartz.batch.config;

import com.gradle.bean.user.User;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindException;

@Component
public class UseFieldMapper implements FieldSetMapper<User> {
    @Override
    public User mapFieldSet(FieldSet fieldSet) throws BindException {
        Long id = fieldSet.readLong("id");
        String userName = fieldSet.readString("userName");
        int age = fieldSet.readInt("age");
       String address =  fieldSet.readString("province")
               + fieldSet.readString("city")
               + fieldSet.readString("area");
        User user = new User();
        user.setId(id);
        user.setUserName(userName);
        user.setAddress(address);
        user.setAge(age);
        return user;
    }
}
